import {WidgetClass} from "../atom/widget";
import {dataBindType} from "@/config/ide/common";

export class SpeechRecognition extends WidgetClass {
  constructor(options = {}) {
    super(options);
    const {states} = options;
    if (states) {
      this.states = states;
      this.state = states[0].id;
    } else {
      const defaultState = this.assembleDefaultState(options);
      this.states = [defaultState];
      this.state = defaultState.id;
    }
  }

  assembleDefaultState(options = {}) {
    const superState = super.assembleDefaultState(options);
    const {callbacks} = options;
    return {
      ...superState,
      valueCtl: {key: "", type: dataBindType.display, dftVal: false},
      callbacks: callbacks || [
        {keyword: "", action: {key: "", type: dataBindType.event, dftVal: false}}
      ]
    };
  }
}
